package com.tenglong.teacher.ui.adapter.viewholder;

import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.BaseHomeWorkInfo;
import com.tenglong.teacher.data.resultInfo.CurrentHomeWorkOutsideInfo;
import com.tenglong.teacher.ui.adapter.HomeWorkAdapter;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;
import com.tenglong.teacher.ui.utils.MyUtils;

/**
 * @author hdx on 2019/3/1.
 */
public class CurrentHomeworkOutsideViewHolder extends BaseViewHolder<BaseHomeWorkInfo> {
    private TextView time,classes,content,submitCase;
    private CurrentHomeWorkOutsideInfo data;
    private HomeWorkAdapter.HomeworkListener listener;

    public CurrentHomeworkOutsideViewHolder(View itemView) {
        super(itemView);
        initView();
        setLisnters();
    }

    public CurrentHomeworkOutsideViewHolder(View itemView, HomeWorkAdapter.HomeworkListener listener) {
        this(itemView);
        this.listener = listener;
    }

    private void setLisnters() {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onClickCurrentItemListener(getLayoutPosition());
                }
            }
        });
    }

    private void initView() {
        time = itemView.findViewById(R.id.time);
        classes = itemView.findViewById(R.id.classes);
        content = itemView.findViewById(R.id.content);
        submitCase = itemView.findViewById(R.id.submitCase);
    }

    @Override
    public void setLayoutInfo(BaseHomeWorkInfo info) {
        this.data = (CurrentHomeWorkOutsideInfo) info;
        time.setText(MyUtils.dateToString(data.createDate));
        classes.setText(data.className==null?"":data.className);
        if( data.countHomework!=0){
            content.setText("第"+data.countHomework+"次作业");
        }else if(data.classNum!=0){
            content.setText("第"+data.classNum+"次作业");
        }else{
            content.setText("第1次作业");
        }
        SpannableStringBuilder builder = new SpannableStringBuilder("提交："+data.submitCount+"/"+data.stuNum);
        builder.setSpan(new ForegroundColorSpan(Color.parseColor("#333333")), 3, 3 + (data.submitCount + "").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        submitCase.setText(builder);
    }
}
